package com.robusta.app.persistence;

import com.robusta.app.model.spreadsheet.persistence.PersistableField;
import com.robusta.app.model.spreadsheet.persistence.PersistableModel;

import static com.robusta.app.persistence.PersistableModelBuilder.PersistableFieldBuilder.newPersistableField;

class PersistableModelBuilder {
    private PersistableModel instance;

    PersistableModelBuilder() {
        instance = new PersistableModel();
    }

    public static PersistableModelBuilder newPersistableModel() {
        return new PersistableModelBuilder();
    }

    public PersistableModelBuilder withDefaults() {
        for(int index = 0; index < 6; index++) {
            instance.add(newPersistableField().withDefaults(index).withModel(instance).build());
        }
        return this;
    }

    public PersistableModel build() {
        return instance;
    }

    static class PersistableFieldBuilder {
        private PersistableField instance;

        private PersistableFieldBuilder() {
            instance = new PersistableField();
        }

        public static PersistableFieldBuilder newPersistableField() {
            return new PersistableFieldBuilder();
        }

        public PersistableField build() {
            return instance;
        }

        public PersistableFieldBuilder withDefaults(int index) {
            instance = new PersistableField("Field::" + index, "FieldValue::" + index, index == 0);
            instance.setValidationMessage("Some message for field::" + index);
            return this;
        }

        public PersistableFieldBuilder withModel(PersistableModel model) {
            instance.setModel(model); return this;
        }
    }
}
